//
//  UIButton+Oval.swift
//  AirlineReservation
//
//  Created by Kevin on 2019/12/26.
//  Copyright © 2019 Kevin. All rights reserved.
//

import UIKit

extension UIButton {
    
    // MARK: 椭圆按钮
    convenience init(title:String,name:String,radius:CGFloat = MARGIN * 1.5) {
        self.init()
        // 文本
        setTitle(title, for: .normal)
        // 颜色
        setBackgroundImage(UIImage(named: name), for: .normal)
        setBackgroundImage(UIImage(named: name + "_highlighted"), for: .highlighted)
        // 裁圆
        layer.masksToBounds = true
        layer.cornerRadius = radius
        //根据背景图片自适应大小
        sizeToFit()
    }
    
    // MARK: 客服按钮
    convenience init(iconName:String,backgroundIconName:String) {
        self.init()
        //设置图片
        setImage(UIImage(named: iconName), for: UIControl.State.normal)
        setImage(UIImage(named: iconName+"_highlighted"), for: UIControl.State.highlighted)
        //设置背景图片
        setBackgroundImage(UIImage(named: backgroundIconName), for: UIControl.State.normal)
        setBackgroundImage(UIImage(named: backgroundIconName+"_highlighted"), for: UIControl.State.normal)
        //根据背景图片自适应大小
        sizeToFit()
    }
    
    // MARK: 设置图片
    convenience init(iconName:String) {
        self.init()
        setImage(UIImage(named: iconName), for: UIControl.State.normal)
        setImage(UIImage(named: iconName+"_highlighted"), for: UIControl.State.highlighted)
    }
    
    // MARK: 设置背景图片
    convenience init(backgroundIconName:String) {
        self.init()
        setBackgroundImage(UIImage(named: backgroundIconName), for: UIControl.State.normal)
        setBackgroundImage(UIImage(named: backgroundIconName+"_highlighted"), for: UIControl.State.highlighted)
    }
}
